import axios from 'axios';
import qs from 'qs'

let base = '/admin';
// 登录接口
export const requestLogin = params => { return axios.post(`${base}/login`, params).then(res => res.data); };
// 菜单列表
export const getMenuList = params => { return axios.get(`${base}/menu/list`, { params: params }); };
// 树状结构
export const getMenuTree = params => { return axios.get(`${base}/menu/tree`, { params: params }); };
// 添加菜单
export const saveMenu = params => { return axios.post(`${base}/menu/save`, params).then(res=>res.data); };
// 删除菜单
export const deleteMenuApi = params => { return axios.delete(`${base}/menu/delete`, { params: params }); };
// 菜单列表
export const getRoleList = params => { return axios.get(`${base}/role/list`, { params: params }); };
// 添加菜单
export const saveRole = params => { return axios.post(`${base}/role/save`, params).then(res=>res.data); };
// 删除菜单
export const deleteRoleApi = params => { return axios.delete(`${base}/role/delete`, { params: params }); };
// 提交权限
export const saveRoleMenus = params => { return axios.post(`${base}/role/saveRoleMenus`, params).then(res=>res.data); };
// 查询管理员列表
export const getAdminListPage = params => { return axios.get(`${base}/user/admins`, { params: params }); };
// 管理员页面获取角色
export const getEnableRole = params => { return axios.get(`${base}/user/roles`, { params: params }); };
// 保存管理员
export const saveAdmin = params => { return axios.post(`${base}/user/admin/save`, params).then(res=>res.data); };

// 用户菜单
export const requestMenus = params => { return axios.get(`${base}/menus`, params).then(res => res.data); };
// 用户
export const getUserListPage = params => { return axios.get(`${base}/user/list`, { params: params }); };
export const saveUser = params => { return axios.post(`${base}/user/save`, params).then(res=>res.data); };
export const removeUser = params => { return axios.delete(`${base}/user/delete`, { params: params }); };

// banner
export const getBannersData = params => { return axios.get(`${base}/banner/list`, { params: params }); };
export const saveBanner = params => { return axios.post(`${base}/banner/save`, params).then(res=>res.data); };
export const bannerStatue = params => { return axios.put(`${base}/banner/state`,params).then(res=>res.data) }
export const deleteBannerApi = params => { return axios.delete(`${base}/banner/delete`, { params: params }); };

// 分类
export const getCategoryData = params => { return axios.get(`${base}/category/list`, { params: params }); };
export const selectParents = params => { return axios.get(`${base}/category/parents`, { params: params }); };
export const getAllCategory = params => { return axios.get(`${base}/category/all`, { params: params }); };
export const saveCategory = params => { return axios.post(`${base}/category/save`, params).then(res=>res.data); };
export const categoryStatus = params => { return axios.put(`${base}/category/state`,params).then(res=>res.data) }
export const deleteCategoryApi = params => { return axios.delete(`${base}/category/delete`, { params: params }); };

// 商品
export const getGoodsData = params => { return axios.get(`${base}/goods/list`, { params: params }); };
export const goodsStatus = params => { return axios.put(`${base}/goods/state`,params).then(res=>res.data) }
export const saveGoodsData = params =>{return axios.post(`${base}/goods/save`,params).then(res=>res.data)}

// 规格
export const getSpecData = params => { return axios.get(`${base}/specification/list`, { params: params }); };
export const saveSpecData = params =>{return axios.post(`${base}/specification/save`,params).then(res=>res.data)}
export const deleteSpecApi = params => { return axios.delete(`${base}/specification/delete`, { params: params }); };
export const getGoodsSpec = params => { return axios.get(`${base}/goods/specs`, { params: params }); };
export const getSpecTree = params => { return axios.get(`${base}/specification/tree`, { params: params }); };
export const saveGoodsSpecData = params =>{return axios.post(`${base}/specification/goods/save`,params).then(res=>res.data)}
export const updateGoodsSpecData = params =>{return axios.post(`${base}/specification/goods/update`,params).then(res=>res.data)}

// 推荐
export const getRecommendData = params => { return axios.get(`${base}/recommend/list`, { params: params }); };
export const saveRecommendData = params =>{return axios.post(`${base}/recommend/save`,params).then(res=>res.data)}
export const deleteRecommendApi = params => { return axios.delete(`${base}/recommend/delete`, { params: params }); };
export const searchGoods = params => { return axios.get(`${base}/goods/search`, { params: params }); };
export const setRecommendGoods = params => { return axios({
    url:`${base}/recommend/save/goods`,
    method: 'post',
    data: qs.stringify(params)
}).then(res=>res.data); };
export const getRecommendGoods = params => { return axios.get(`${base}/recommend/list/goods`, { params: params }); };
export const cancelRecommendGoods = params => { return axios.delete(`${base}/recommend/delete/goods`, { params: params }); };

//  的订单
export const getOrderData = params => { return axios.get(`${base}/order/list`, { params: params }); };
export const updateOrder = params =>{return axios.post(`${base}/order/update`,params).then(res=>res.data)}
export const saveSendGoods = params =>{return axios.post(`${base}/order/send`,params).then(res=>res.data)}
export const refundOrder = params =>{return axios.post(`${base}/order/refund`,params).then(res=>res.data)}
export const rejectOrder = params =>{return axios.post(`${base}/order/reject`,params).then(res=>res.data)}
export const deleteOrder = params => { return axios.delete(`${base}/order/delete`, { params: params }); };


// 快递
export const getExpressList = params => { return axios.get(`${base}/express/list`, { params: params }); };
export const getAllExpress = params => { return axios.get(`${base}/express/list/all`, { params: params }); };
export const saveExpressData = params =>{return axios.post(`${base}/express/save`,params).then(res=>res.data)}
export const deleteExpress = params => { return axios.delete(`${base}/express/delete`, { params: params }); };
